package com.st.mall.product.app;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.st.mall.product.vo.CategoryBrandRelationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.st.mall.product.entity.CategoryBrandRelationEntity;
import com.st.mall.product.service.CategoryBrandRelationService;
import com.st.common.utils.PageUtils;
import com.st.common.utils.R;



/**
 * 品牌分类关联
 *
 * @author fg
 * @email f@163.com
 * @date 2023-02-26 20:46:23
 */
@RestController
@RequestMapping("product/categoryBrandRelation")
public class CategoryBrandRelationController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = categoryBrandRelationService.queryPage(params);
        return R.ok().put("page", page);
    }
    /**
     * 获取分类关联的品牌
     */
    @GetMapping("/brands/list")
    public R relationList(@RequestParam("catId") Long catId){
        List<CategoryBrandRelationEntity> list = categoryBrandRelationService.getRelationList(catId);
        return R.ok().put("data", list);
    }

    /**
     *获取品牌关联的分类
     */
    @GetMapping("/cateLog/list")
    public R cateLogList(@RequestParam("brandId") Long brandId){
        List<CategoryBrandRelationVo> list= categoryBrandRelationService.getCateLogList(brandId);

        return R.ok().put("data",list);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")

    public R info(@PathVariable("id") Long id){
		CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);

        return R.ok().put("categoryBrandRelation", categoryBrandRelation);
    }

    /**
     * 新增品牌与分类关联关系
     */
    @PostMapping("/save")
    public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelationEntity){
		categoryBrandRelationService.saveCas(categoryBrandRelationEntity);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.updateById(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] ids){
		categoryBrandRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
